﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Quality.Records
{
    public partial class selectpro : Form
    {
        public selectpro()
        {
            InitializeComponent(); 
           
            this.dataGridView1.AutoGenerateColumns = false;
            frm_TransfEvent();
        }

        private void 查询toolStripButton1_Click(object sender, EventArgs e)
        {
            frm_TransfEvent();
        }
        //事件处理方法
        void frm_TransfEvent()
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand();
            if (keytoolStripTextBox.Text == "")
            {

                da.SelectCommand.CommandText = "select  a.id,a.num,a.proname,a.specification,a.unit1,b.cusname,c.supname,d.typename,d.num typenum from products a left join customers b on a.customer=b.num left join suppliers c on a.supplier=c.num left join  testtypes d on a.testtype=d.num where a.stop=0 order by a.id desc";

            }
            else
            {

                da.SelectCommand.CommandText = "select a.id,a.num,a.proname,a.specification,a.unit1,b.cusname,c.supname,d.typename,d.num typenum from products a left join customers b on a.customer=b.num left join suppliers c on a.supplier=c.num left join  testtypes d on a.testtype=d.num where a.num like '%@key%' or a.proname like '%@key%' and a.stop=0 order by a.id desc";
                da.SelectCommand.Parameters.AddWithValue("@key", keytoolStripTextBox.Text.Trim());

            }
            DataSet dt = DB.getlist(da);
            dataGridView1.DataSource = dt.Tables[0];

        }

       
        public event TransfDelegate TransfEvent;
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string[] d = new string[4];
            if (dataGridView1.SelectedRows.Count > 0)
            {           
                d[0] = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                d[1] = dataGridView1.CurrentRow.Cells[2].Value.ToString();
                d[2] = dataGridView1.CurrentRow.Cells[7].Value.ToString();
                d[3] = dataGridView1.CurrentRow.Cells[8].Value.ToString();
                TransfEvent(d);
                this.Close();

            }
        }

    }
}
